import { TUser } from '../Types/user'
import request from '../utils/request'

// 获取用户
export const getUserService = (data: { currentPage: number; pageSize: number }) => {
	return request({
		url: '/public/users',
		method: 'get',
		params: data
	})
}

// 获取指定用户
export const getUserByUserInfoService = (data: any) => {
	return request({
		url: `/public/users/specific`,
		method: 'get',
		params: data
	})
}

// 删除用户
export const deleteUserService = (userId: number) => {
	return request({
		url: `/public/users/${userId}`,
		method: 'delete'
	})
}

// 添加用户
export const addUserService = (data: TUser) => {
	return request({
		url: `/public/users`,
		method: 'post',
		data: {
			...data
		}
	})
}

/**
 * 添加用户列表
 */
export const addUserListService = (data: any[]) => {
	return request({
		url: '/public/users/list',
		method: 'post',
		data
	})
}

// 修改用户
export const updateUserService = (data: any) => request.put(`/public/users`, data)

/**
 * 批量添加用户（基于文件上传）
 * @param data 用户数据
 * @returns {Promise}
 */
export const addUserBatchService = (data: FormData) => {
	return request({
		url: '/public/users/batch',
		method: 'post',
		data,
		headers: {
			'Content-Type': 'multipart/form-data'
		}
	})
}
